import 'package:flutter/material.dart';
import 'package:order_hybrid/components/OrderItem.dart';
import 'package:order_hybrid/components/OrderTabBar.dart';


class OrderPage extends StatefulWidget {
  const OrderPage({super.key});

  @override
  State<OrderPage> createState() => _OrderPageState();
}

class _OrderPageState extends State<OrderPage>
    with SingleTickerProviderStateMixin {
  late TabController _tabController;
  final List<String> _tabs = ['全部', '待付款', '待发货', '待收货', '待评价'];

   final List<Map<String, dynamic>> _orderList = [
    {
      'id': '1001',
      'createTime': '2024-01-15 18:03:24',
      'payType': 1,
      'orderState': 1,
      'payLatestTime': '2024-01-15 19:03:24',
      'postFee': 0,
      'payMoney': 25.00,
      'totalMoney': 25.00,
      'totalNum': 1,
      'skus': [
        {
          'id': 'sku001',
          'spuId': 'spu001',
          'name': 'DIOR 迪奥 LADY D-JOY 中号羊皮格纹女士手提包',
          'quantity': 1,
          'image': 'assets/images/bag.png',
          'realPay': 25.00,
          'curPrice': 25.00,
          'totalMoney': 25.00,
          'properties': [
            {
              'propertyMainName': '颜色',
              'propertyValueName': '黑色'
            },
            {
              'propertyMainName': '尺码',
              'propertyValueName': 'L'
            }
          ],
          'attrsText': '黑色 L'
        }
      ],
      'payChannel': 1,
      'countdown': 3600
    },
    {
      'id': '1002',
      'createTime': '2024-01-15 17:03:24',
      'payType': 1,
      'orderState': 2,
      'payLatestTime': '2024-01-15 18:03:24',
      'postFee': 0,
      'payMoney': 25.00,
      'totalMoney': 25.00,
      'totalNum': 1,
      'skus': [
        {
          'id': 'sku002',
          'spuId': 'spu001',
          'name': 'DIOR 迪奥 LADY D-JOY 中号羊皮格纹女士手提包',
          'quantity': 1,
          'image': 'assets/images/bag.png',
          'realPay': 25.00,
          'curPrice': 25.00,
          'totalMoney': 25.00,
          'properties': [
            {
              'propertyMainName': '颜色',
              'propertyValueName': '红色'
            },
            {
              'propertyMainName': '尺码',
              'propertyValueName': 'M'
            }
          ],
          'attrsText': '红色 M'
        }
      ],
      'payChannel': 1,
      'countdown': 3600
    }
  ];
  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: _tabs.length, vsync: this);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xFFF5F5F5),
      body: Column(
        children: [
          OrderTabBar(
            tabs: _tabs,
            controller: _tabController,
          ),
          Expanded(
            child: ListView.builder(
              padding: const EdgeInsets.symmetric(horizontal: 12),
              itemCount: _orderList.length,
              itemBuilder: (context, index) {
                return OrderItem(
                  orderInfo: _orderList[index],
                );
              },
            ),
          ),
        ],
      ),
    );
  }
}
